package com.da.javatest.demo.basic;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;

public class HashTest {
    public static void main(String[] args) {
        List<Student> students1 = Arrays.asList(new Student(1, "aa", 18), new Student(2, "bb", 19),
            new Student(3, "cc", 18), new Student(4, "aa", 19));
        System.out.println(students1);
        HashSet<Student> students2 = new HashSet<>(students1);
        System.out.println(students2);
    }

}

class Student {
    private Integer id;
    private String name;
    private Integer age;

    public Student(Integer id, String name, Integer age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
            "id=" + id +
            ", name='" + name + '\'' +
            ", age=" + age +
            '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) { return true; }
        if (o == null || getClass() != o.getClass()) { return false; }
        Student student = (Student)o;
        return Objects.equals(name, student.name);
    }

    //@Override
    //public int hashCode() {
    //    return Objects.hash(name);
    //}

}
